package com.hippo.core.utils

import android.content.Context
import android.content.Context.MODE_PRIVATE
import android.content.SharedPreferences
import android.content.res.Configuration
import android.content.res.Resources
import android.util.Log
import java.util.Locale


object LanguageUtil {

    fun setAppLocale(context : Context, languageCode:String){

        Log.i("LanguageUtil", "setAppLocale: $languageCode")

        val sharedPreferences: SharedPreferences = context.getSharedPreferences("Settings", MODE_PRIVATE)
        val editor = sharedPreferences.edit()
        editor.putString("language", languageCode)
        editor.apply()

        val resources: Resources = context.resources
        val configuration: Configuration = resources.configuration
        val locale: Locale = Locale(languageCode)
        Locale.setDefault(locale)
        configuration.setLocale(locale)
        resources.updateConfiguration(configuration, resources.displayMetrics)
    }



}